const common = require('../../utils/common.js');
var that = "";
//时间控件
const date = new Date()
const years = []
const months = []
const days = []

for (let i = 1990; i <= date.getFullYear(); i++) {
  years.push(i)
}

for (let i = 1; i <= 12; i++) {
  months.push(i)
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listData: [],
    totalfee: 0,
    dete: "",
    //以下为时间选择变量
    years: years,
    year: date.getFullYear(),
    months: months,
    month: date.getMonth() + 1,
    days: days,
    day: date.getDate(),
    value: [9998, 0, 0],
    modalHidden: true,//默认隐藏moal
  },

  initData: function (month) {
    common._get('/wx/uncollected', { month: month},
      //成功
      function (res) {
        if (res.data.success) {
          console.log('res.data.data');
          console.log(res.data.data);
          that.setData({
            listData: res.data.data.list,
            totalfee: res.data.data.totalfee,
          })
        }
      });
  },
  /**
   * 点击每一项费用
   */
  chargesItemClick: function (e) {
    var chargeid = e.currentTarget.dataset.chargeid
    wx.navigateTo({
      url: '../receiptDetails/receiptDetails?chargeid=' + chargeid,
    })
  },

  //时间modal改变监听
  bindChange: function (e) {
    const val = e.detail.value
    this.setData({
      year: this.data.years[val[0]],
      month: this.data.months[val[1]],
    })
  },
  //显示
  showModel: function () {

    that.setData({
      modalHidden: false,
    })
  },
  //modal确认取消
  //确认
  confirm: function () {
    this.setData({
      modalHidden: true,
    })
    this.setMyDeta();
    this.initData(that.data.year + '-' + that.data.month + '-1');
  },
  //取消
  cancel: function () {
    this.setData({
      modalHidden: true,
    })
  },
  //设置时间绑定
  setMyDeta: function () {
    that.setData({
      dete: that.data.year + '年' + that.data.month + '月'
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    that = this;
    this.setData({
      value: [9999, this.data.month - 1, this.data.day - 1],
    })
    this.setMyDeta();
    that.initData("");
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var refresh = wx.getStorageSync('refresh');
    wx.removeStorageSync('refresh');
    if (refresh) {
      that.initData(that.data.year + '-' + that.data.month + '-1');
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.initData(that.data.year + '-' + that.data.month + '-1');
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})